
*Covariates in CZ of destination
clear all
set more off

use "$final_data_covariates/czone1990_Covariates.dta", clear
merge 1:m czone using "$final_data_outcomes/czone_Students.dta", assert(3) nogenerate
merge 1:1 czone year using "$final_data_automation/czones_ExposureAutomation", assert(3) nogenerate
merge 1:1 czone year using "$final_data_imports/czone_ExposureChina", assert(3) nogenerate
merge m:1 czone using "$final_data_covariates/IPEDS_institutionControlsCZ.dta", assert(1 3) nogenerate

foreach var in public private uniTop30Dummy largest150 anyAid {
replace `var' = 0 if mi(`var')
}

keep if year==1990

keep czone $occupations_1990 $demographics_1990 $industry_shares_1990 $institutions_1990 d_exp_iv_stacked d_sc_70_90 ipums_pop_1990 division statefip

foreach var of varlist $occupations_1990 $demographics_1990 $industry_shares_1990 $institutions_1990 d_exp_iv_stacked d_sc_70_90 ipums_pop_1990 division statefip {
rename `var' `var'_d
}

rename czone toczone

save "$final_data_covariates/toczone1990_Covariates.dta", replace

clear all
set more off

use "$final_data_covariates/czone1990_Covariates.dta", clear
merge 1:m czone using "$final_data_outcomes/czone_Students.dta", assert(3) nogenerate
merge 1:1 czone year using "$final_data_automation/czones_ExposureAutomation", assert(3) nogenerate
merge 1:1 czone year using "$final_data_imports/czone_ExposureChina", assert(3) nogenerate
merge m:1 czone using "$final_data_covariates/IPEDS_institutionControlsCZ.dta", assert(1 3) nogenerate

foreach var in public private uniTop30Dummy largest150 anyAid {
replace `var' = 0 if mi(`var')
}

keep if year==1990

keep czone $occupations_1990 $demographics_1990 $industry_shares_1990 $institutions_1990 d_exp_iv_stacked d_sc_70_90 ipums_pop_1990 division statefip

foreach var of varlist $occupations_1990 $demographics_1990 $industry_shares_1990 $institutions_1990 d_exp_iv_stacked d_sc_70_90 ipums_pop_1990 division statefip {
rename `var' `var'_o
}

rename czone fromczone

save "$final_data_covariates/fromczone1990_Covariates.dta", replace
